using System;
using System.Collections.Generic;
using System.Drawing;

namespace ImageCSharp.Core.Models
{
    /// <summary>
    /// 魔术棒工具
    /// </summary>
    public class MagicWandTool : Tool
    {
        public MagicWandTool()
        {
            Type = ToolType.MagicWand;
            Name = "魔术棒工具";
            Description = "基于颜色相似性选择图像区域";
            IconPath = "MagicWand";
            
            Properties.Add("Tolerance", 0.1f);
            Properties.Add("AntiAlias", true);
            Properties.Add("Contiguous", true);
            Properties.Add("SampleAllLayers", false);
            Properties.Add("Mode", MagicWandSelectionMode.Replace);
        }

        public float Tolerance 
        { 
            get => (float)Properties["Tolerance"]; 
            set => Properties["Tolerance"] = Math.Max(0f, Math.Min(1f, value)); 
        }

        public bool AntiAlias 
        { 
            get => (bool)Properties["AntiAlias"]; 
            set => Properties["AntiAlias"] = value; 
        }

        public bool Contiguous 
        { 
            get => (bool)Properties["Contiguous"]; 
            set => Properties["Contiguous"] = value; 
        }

        public bool SampleAllLayers 
        { 
            get => (bool)Properties["SampleAllLayers"]; 
            set => Properties["SampleAllLayers"] = value; 
        }

        public MagicWandSelectionMode Mode 
        { 
            get => (MagicWandSelectionMode)Properties["Mode"]; 
            set => Properties["Mode"] = value; 
        }

        /// <summary>
        /// 获取容差百分比显示
        /// </summary>
        public string GetToleranceDisplay()
        {
            return $"{Tolerance * 100:F1}%";
        }

        /// <summary>
        /// 获取选择模式显示
        /// </summary>
        public string GetModeDisplay()
        {
            return Mode switch
            {
                MagicWandSelectionMode.Replace => "替换",
                MagicWandSelectionMode.Add => "添加",
                MagicWandSelectionMode.Subtract => "减去",
                MagicWandSelectionMode.Intersect => "交集",
                _ => "替换"
            };
        }
    }

    /// <summary>
    /// 选择模式
    /// </summary>
    public enum MagicWandSelectionMode
    {
        Replace,
        Add,
        Subtract,
        Intersect
    }
}